<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	Tekuna :: load('org.tekuna.core.filter.TekunaFilter');


	/**
	 * This filter is an adapter class to use PHP's filter facilities
	 * with Tekuna. Example:
	 *
	 * PHP:
	 *      filter_var($sInput, FILTER_SANITIZE_STRIPPED);
	 *
	 * Tekuna:
	 *      new PHPInternalFilter(FILTER_SANITIZE_STRIPPED);
	 */

	class PHPInternalFilter implements TekunaFilter {

		protected
			$iFilterType = 0,
			$mOptions = NULL;


		/**
		 * Construct a new filter adapter for a given filter type
		 *
		 * @param int $iFilterType the int-ID of the filter type (usually as constant)
		 * @param mixed $mOptions optional; if the used filter requires additionnaly options
		 */

		public function __construct($iFilterType, $mOptions = NULL) {

			$this -> iFilterType = $iFilterType;
			$this -> mOptions = $mOptions;
		}


		/**
		 * Applies the filter with the given input with the filter_var() function.
		 *
		 * @param mixed $mInput
		 * @return mixed the output
		 */

		public function filter($mInput) {

			if ($this -> mOptions === NULL) {

				return filter_var($mInput, $this -> iFilterType);
			}
			else {

				return filter_var($mInput, $this -> iFilterType, $this -> mOptions);
			}
		}
	}
